﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Data;
using BySoft.Server.Consts;
using System.Data.OleDb;
//using System.Net.Mail;
//using System.Net;
using OneSoft.DataAccess;
using System.Configuration;
using System.Web;
using System.Web.Mail;
using System.Web.Util;
using System.IO;
using System.Data.Odbc;
using System.Reflection;
using System.Net;
using System.Net.Mail;
using BySoft.Server.Common.Entity;
using System.Web.UI.WebControls;
using System.Web.UI;
using OneSoft.Web;
using System.Web.UI.HtmlControls;

namespace BySoft.Server.Common
{
    public class CommonMethod
    {
        public static decimal ConvertToDecimalWithoutZero(object obj, int iLen)
        {
            if (null == obj)
            {
                return 0;
            }
            decimal tep = 0;
            decimal.TryParse(obj.ToString(), out tep);
            string[] strs = Math.Round(tep, iLen).ToString().Split('.');
            string str = strs[0];
            if (strs.Length > 1 &&
                !string.IsNullOrEmpty(strs[1]))
            {
                int icount = strs[1].Length;
                for (int i = strs[1].Length - 1; i >= 0; i--)
                {
                    if (strs[1][i] == '0')
                    {
                        icount--;
                    }
                    else
                    {
                        break;
                    }
                }

                if (icount != 0)
                {
                    if (icount == strs[1].Length)
                    {
                        str += "." + strs[1];
                    }
                    if (icount < strs[1].Length)
                    {
                        str += "." + strs[1].Substring(0, icount);
                    }
                }

            }
            tep = 0;
            decimal.TryParse(str, out tep);
            return tep;
        }

        public static decimal ConvertToDecimalWithoutZero(object obj)
        {
            if (null == obj)
            {
                return 0;
            }
            decimal tep = 0;
            decimal.TryParse(obj.ToString(), out tep);
            string[] strs = tep.ToString().Split('.');
            string str = strs[0];
            if (strs.Length > 1 &&
                !string.IsNullOrEmpty(strs[1]))
            {
                int icount = strs[1].Length;
                for (int i = strs[1].Length - 1; i >= 0; i--)
                {
                    if (strs[1][i] == '0')
                    {
                        icount--;
                    }
                    else
                    {
                        break;
                    }
                }

                if (icount != 0)
                {
                    if (icount == strs[1].Length)
                    {
                        str += "." + strs[1];
                    }
                    if (icount < strs[1].Length)
                    {
                        str += "." + strs[1].Substring(0, icount);
                    }
                }

            }
            tep = 0;
            decimal.TryParse(str, out tep);
            return tep;
        }

        public static string GetDecimalWithoutZero(object obj)
        {
            if (null == obj)
            {
                return "0";
            }
            decimal tep = 0;
            decimal.TryParse(obj.ToString(), out tep);
            string[] strs = tep.ToString().Split('.');
            string str = strs[0];
            if (strs.Length > 1 &&
                !string.IsNullOrEmpty(strs[1]))
            {
                int icount = strs[1].Length;
                for (int i = strs[1].Length - 1; i >= 0; i--)
                {
                    if (strs[1][i] == '0')
                    {
                        icount--;
                    }
                    else
                    {
                        break;
                    }
                }

                if (icount != 0)
                {
                    if (icount == strs[1].Length)
                    {
                        str += "." + strs[1];
                    }
                    if (icount < strs[1].Length)
                    {
                        str += "." + strs[1].Substring(0, icount);
                    }
                }

            }
            tep = 0;
            decimal.TryParse(str, out tep);
            return tep.ToString();
        }
        public static DataTable CopyDTtoDT(DataTable dtOri, DataTable dtCur)
        {
            if (null == dtOri || dtOri.Rows.Count < 1 || null == dtCur)
            {
                return null;
            }
            DataTable dttemp = dtCur.Copy();
            foreach (DataRow row in dtOri.Rows)
            {
                DataRow dr = dttemp.NewRow();
                foreach (DataColumn col in dtCur.Columns)
                {
                    dr[col.ColumnName] = row[col.ColumnName];
                }
                dttemp.Rows.Add(dr);
            }
            return dttemp;
        }

        public static string CutStr(string str)
        {
            return CutStr(str, 25);
        }

        public static bool LenStr(string str, int length)
        {
            if (string.IsNullOrEmpty(str))
            {
                return true;
            }
            int len = length * 2;
            int j = 0, k = 0;
            Encoding encoding = Encoding.GetEncoding("gb2312");

            for (int i = 0; i < str.Length; i++)
            {
                byte[] bytes = encoding.GetBytes(str.Substring(i, 1));
                if (bytes.Length == 2)//不是英文
                    j += 2;
                else
                    j++;

                if (j <= len)
                    k += 1;

                if (j > len)
                    return false;
            }
            return true;
        }

        /// <summary>
        /// 取得指定长度的字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string CutStr(string str, int length)
        {
            if (str == null)
                return string.Empty;

            int len = length * 2;
            int j = 0, k = 0;
            Encoding encoding = Encoding.GetEncoding("gb2312");

            for (int i = 0; i < str.Length; i++)
            {
                byte[] bytes = encoding.GetBytes(str.Substring(i, 1));
                if (bytes.Length == 2)//不是英文
                    j += 2;
                else
                    j++;

                if (j <= len)
                    k += 1;

                if (j >= len)
                    return str.Substring(0, k) + "...";
            }
            return str;
        }

        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static String Encrypt(String text)
        {
            Byte[] inputBytes = Encoding.ASCII.GetBytes(text);
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            Byte[] outputBytes = md5Hasher.ComputeHash(inputBytes);
            String ret = BitConverter.ToString(outputBytes);
            ret = ret.Replace("-", String.Empty);
            return ret;
        }

        public static String GetStartTime(object obj)
        {
            if (null == obj)
            {
                return "";
            }
            string str = obj.ToString();
            return string.IsNullOrEmpty(str) ? "" : Convert.ToDateTime(str).ToString("yyyy-MM-dd 00:00:00");
        }

        public static String GetEndTime(object obj)
        {
            if (null == obj)
            {
                return "";
            }
            string str = obj.ToString();
            return string.IsNullOrEmpty(str) ? "" : Convert.ToDateTime(str).ToString("yyyy-MM-dd 23:59:59");
        }

        public static string GetSpecifications(string str)
        {
            return str.Replace(" ", "  ").Trim();
        }

        public static bool IsNumericWithMin(object o)
        {
            if (o == null||o.ToString()=="")
                return false;

            string strNum = o.ToString();
            System.Text.RegularExpressions.Regex reg1
                = new System.Text.RegularExpressions.Regex(@"^-?[0-9]*(\.[0-9]*)?$");
            return reg1.IsMatch(strNum);
        }

        public static bool IsNumeric(object o)
        {
            if (o == null || o.ToString() == "")
                return false;

            string strNum = o.ToString();
            System.Text.RegularExpressions.Regex reg1
                = new System.Text.RegularExpressions.Regex(@"^-?[0-9]*$");
            return reg1.IsMatch(strNum);
        }

        public static string DugeIntOrDecimal(string num)
        {
            if (num.ToString().Length <= 18)
            {
                int dotcur = num.IndexOf('.');

                string[] gnum = num.Split('.');
                if (gnum.Length > 1)
                {
                    if (gnum[1].ToString() == "0000")
                    {
                        return num = Convert.ToInt64(Convert.ToDecimal(gnum[0])).ToString();
                    }
                    else
                    {
                        return num.ToString();
                    }
                }
                else
                {
                    //for (int i = num.Length - 1; i > dotcur; i--)
                    //{
                    //    if (!num[i].Equals('0'))
                    //    {
                    //        if (num.ToString().Length <= 18)
                    //        {
                    //            num = Convert.ToDecimal(num).ToString();
                    //        }
                    //        return num.ToString();
                    //    }
                    //}
                    num = Convert.ToInt64(Convert.ToDecimal(num)).ToString();
                    return num.ToString();
                }
            }
            else
            {
                return num.ToString();
            }
        }

        public static void BindYear(DropDownList ddl)
        {
            int year= int.Parse(ConfigurationManager.AppSettings["MaxYear"].ToString());
            for (int i = year; i >= 2000; i--)
            {
                ddl.Items.Insert(0, new ListItem(i.ToString(), i.ToString()));
            }
           
                ddl.SelectedValue = System.DateTime.Now.Year.ToString();
            
        }

        public static void BindMonth(DropDownList ddl,bool tf)
        {
            for (int i = 12; i >= 1; i--)
            {
                if (tf == false)
                {
                    ddl.Items.Insert(0, new ListItem(i.ToString(), i.ToString()));
                }
                if (tf == true)
                {
                    if (i == 12 || i == 9 || i == 6 || i == 3)
                    {
                        ddl.Items.Insert(0, new ListItem(i.ToString(), i.ToString()));
                    }
                }
            }
            
                if (tf == false)
                {
                    ddl.SelectedValue = System.DateTime.Now.Month.ToString();
                }
                if (tf == true)
                {
                    if (System.DateTime.Now.Month == 12 || System.DateTime.Now.Month == 9 || System.DateTime.Now.Month == 6 || System.DateTime.Now.Month == 3)
                    {
                        ddl.SelectedValue = System.DateTime.Now.Month.ToString();
                    }
                }
            
        }

        #region 从Excel读取数据
        public static DataTable GetDataFromExcel(HttpPostedFile postFile, ref string errorMsg)
        {
            return GetDataFromExcel("Sheet1", postFile, ref errorMsg);
        }

        /// <summary>
        ///  从Excel读取数据
        /// </summary>
        /// <param name="strFileName">文件名称</param>
        /// <param name="strFileName">Sheet名称</param>
        /// <returns></returns>
        public static DataTable GetDataFromExcel(string strSheetName, HttpPostedFile postFile, ref string errorMsg)
        {
            if (String.IsNullOrEmpty(postFile.FileName))
            {
                errorMsg = Message.ChooseFile;
                return null;
            }
            if (!(postFile.FileName.ToUpper().EndsWith(".XLS") || postFile.FileName.ToUpper().EndsWith(".XLSX")))
            {
                errorMsg = Message.ChooseExcelFile;
                return null;
            }
            else if (postFile.FileName.ToUpper().EndsWith(".XLSX"))
            {
                errorMsg = Message.ChooseXLSFile;
                return null;
            }
            int nMaxLength = int.Parse(ConfigurationManager.AppSettings["UploadFileMaxLenth"].ToString());
            if (postFile.ContentLength >= nMaxLength * 1024 * 1024)
            {
                errorMsg = String.Format(Message.FileCannotBiggerThen4M, nMaxLength.ToString());
                return null;
            }

            string[] sTemp = postFile.FileName.Split('\\');

            postFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);

            string strConn = "";
            if (postFile.FileName.ToUpper().EndsWith(".XLS"))
            {
                strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1] + ";" +
                     "Extended Properties='Excel 8.0;IMEX=1'";
            }
            else
            {
                strConn = "Provider=Microsoft.ACE.OLEDB.12.0" +
                     "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1] + ";" +
                     "Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
            }
            OleDbConnection objConn = new OleDbConnection(strConn);
            objConn.Open();
            DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new[] { null, null, null, "Table" });

            OleDbDataAdapter ExcelDA = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", dt.Rows[0]["TABLE_NAME"].ToString()), strConn);

            DataSet ExcelDs = new DataSet();
            try
            {
                ExcelDA.Fill(ExcelDs, "ExcelInfo");
            }
            catch 
            {
                //errorMsg = Message.ExcelError;
                //return null;
            }
            finally
            {
                objConn.Close();
                File.Delete(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);
            }
            return ExcelDs.Tables[0];
        }
        #endregion

        /// <summary>
        /// 从CSV文件读取数据
        /// </summary>
        /// <param name="postFile"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public static DataTable GetDataFromCSV(HttpPostedFile postFile, ref string errorMsg)
        {
            if (String.IsNullOrEmpty(postFile.FileName))
            {
                errorMsg = Message.ChooseFile;
                return null;
            }
            if (!(postFile.FileName.ToUpper().EndsWith(".CSV")))
            {
                errorMsg = String.Format(String.Format(Message.PleaseSelect, "CSV文件"));
                return null;
            }
            int nMaxLength = int.Parse(ConfigurationManager.AppSettings["UploadFileMaxLenth"].ToString());
            if (postFile.ContentLength >= nMaxLength * 1024 * 1024)
            {
                errorMsg = String.Format(Message.FileCannotBiggerThen4M, nMaxLength.ToString());
                return null;
            }

            string[] sTemp = postFile.FileName.Split('\\');

            postFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);

            //string strconn = @"driver={microsoft text driver (*.txt; *.csv)};dbq=";
            //strconn += System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/");
            //strconn += ";extensions=asc,csv,tab,txt;";

            //OdbcConnection objconn = new OdbcConnection(strconn);
            //DataSet dscsv = new DataSet();
            DataTable dtData = new DataTable();
            try
            {

                StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);

                string sContent = sr.ReadToEnd();
                sContent = sContent.Replace("\r\n", "^");
                string[] sLine = sContent.Split('^');
                bool isRight = true;
                int nLine = 0;
                for (int i = 0; i < sLine.Length; i++)
                {
                    if (!string.IsNullOrEmpty(sLine[i]))
                    {
                        string[] sCell = sLine[i].Split(',');
                        if (dtData.Columns.Count == 0)
                        {
                            for (int j = 0; j < sCell.Length; j++)
                            {
                                dtData.Columns.Add();
                            }
                        }
                        if (sCell.Length != dtData.Columns.Count)
                        {
                            nLine = i + 1;
                            isRight = false;
                            break;
                        }
                        DataRow dr = dtData.NewRow();
                        for (int j = 0; j < sCell.Length; j++)
                        {
                            dr[j] = sCell[j].ToString();
                        }
                        dtData.Rows.Add(dr);
                    }
                }
                if (!isRight)
                {
                    errorMsg = "第" + nLine.ToString() + "行数据格式错误，请检查！";

                    return null;
                }
                sr.Close();
                //string strsql = "select * from " + sTemp[sTemp.Length - 1];
                //OdbcDataAdapter odbccsvdataadapter = new OdbcDataAdapter(strsql, objconn);

                //odbccsvdataadapter.Fill(dscsv);
            }
            catch
            {
                //return null;
            }
            finally
            {
                File.Delete(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);
            }
            //return dscsv.Tables[0];
            return dtData;

        }

        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="mailTitle"></param>
        /// <param name="mailContent"></param>
        /// <param name="to"></param>
        public static void SendMail(string mailTitle, string mailContent, string to)
        {
            string sHost = ConfigurationManager.AppSettings["Mail_Host"].ToString();
            string sUserName = ConfigurationManager.AppSettings["Mail_user"].ToString();
            string sPwd = ConfigurationManager.AppSettings["Mail_pwd"].ToString();
            string sFrom = ConfigurationManager.AppSettings["Mail_From"].ToString();


            //System.Web.Mail.MailMessage objMailMessage = new System.Web.Mail.MailMessage();
            //objMailMessage.From = sFrom;
            //objMailMessage.To = to;
            //objMailMessage.Subject = mailTitle;
            //objMailMessage.Body = mailContent;

            ////基本权限 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            ////用户名 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sUserName);
            ////密码 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sPwd);
            ////SMTP地址 
            //SmtpMail.SmtpServer = sHost;
            ////开始发送邮件 
            //SmtpMail.Send(objMailMessage);

            MailAddress from = new MailAddress(sFrom);
            MailAddress mto = new MailAddress(to);

            System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage(from, mto);

            objMailMessage.Priority = System.Net.Mail.MailPriority.High;

            objMailMessage.Subject = mailTitle;
            objMailMessage.Body = mailContent;

            SmtpClient client = new SmtpClient(sHost);
            client.UseDefaultCredentials = true;
            client.Credentials = new NetworkCredential(sUserName, sPwd);
            client.Send(objMailMessage);
        }
        /// <summary>
        /// 以Web内容形式发送邮件
        /// </summary>
        /// <param name="mailTitle"></param>
        /// <param name="mailContent"></param>
        /// <param name="to"></param>
        public static void SendMailByHtml(string mailTitle, string mailContent, string to)
        {
            string sHost = ConfigurationManager.AppSettings["Mail_Host"].ToString();
            string sUserName = ConfigurationManager.AppSettings["Mail_user"].ToString();
            string sPwd = ConfigurationManager.AppSettings["Mail_pwd"].ToString();
            string sFrom = ConfigurationManager.AppSettings["Mail_From"].ToString();


            //System.Web.Mail.MailMessage objMailMessage = new System.Web.Mail.MailMessage();
            //objMailMessage.From = sFrom;
            //objMailMessage.To = to;
            //objMailMessage.Subject = mailTitle;
            //objMailMessage.Body = mailContent;

            ////基本权限 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            ////用户名 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sUserName);
            ////密码 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sPwd);
            ////SMTP地址 
            //SmtpMail.SmtpServer = sHost;
            ////开始发送邮件 
            //SmtpMail.Send(objMailMessage);

            MailAddress from = new MailAddress(sFrom);
            MailAddress mto = new MailAddress(to);

            System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage(from, mto);

            objMailMessage.Priority = System.Net.Mail.MailPriority.High;
            objMailMessage.IsBodyHtml = true;

            objMailMessage.Subject = mailTitle;
            objMailMessage.Body = mailContent;

            SmtpClient client = new SmtpClient(sHost);
            client.UseDefaultCredentials = true;
            client.Credentials = new NetworkCredential(sUserName, sPwd);
            client.Send(objMailMessage);
        }

        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="mailTitle"></param>
        /// <param name="mailContent"></param>
        /// <param name="to"></param>
        public static void SendMailAttach(string mailTitle, string mailContent, string to, string attach)
        {
            string sHost = ConfigurationManager.AppSettings["Mail_Host"].ToString();
            string sUserName = ConfigurationManager.AppSettings["Mail_user"].ToString();
            string sPwd = ConfigurationManager.AppSettings["Mail_pwd"].ToString();
            string sFrom = ConfigurationManager.AppSettings["Mail_From"].ToString();


            //System.Web.Mail.MailMessage objMailMessage = new System.Web.Mail.MailMessage();
            //objMailMessage.From = sFrom;
            //objMailMessage.To = to;
            //objMailMessage.Subject = mailTitle;
            //objMailMessage.Body = mailContent;

            ////基本权限 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            ////用户名 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sUserName);
            ////密码 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sPwd);
            ////SMTP地址 
            //SmtpMail.SmtpServer = sHost;
            ////开始发送邮件 
            //SmtpMail.Send(objMailMessage);

            MailAddress from = new MailAddress(sFrom);
            MailAddress mto = new MailAddress(to);
            Attachment att = new Attachment(AppDomain.CurrentDomain.BaseDirectory + attach);

            System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage(from, mto);

            objMailMessage.Priority = System.Net.Mail.MailPriority.High;

            objMailMessage.Subject = mailTitle;
            objMailMessage.Body = mailContent;
            objMailMessage.Attachments.Add(att);

            SmtpClient client = new SmtpClient(sHost);
            client.UseDefaultCredentials = true;
            client.Credentials = new NetworkCredential(sUserName, sPwd);
            client.Send(objMailMessage);
        }
        /// <summary>
        /// 以Web内容形式并且带附件发送邮件
        /// </summary>
        /// <param name="mailTitle"></param>
        /// <param name="mailContent"></param>
        /// <param name="to"></param>
        public static void SendMailByHtmlAttach(string mailTitle, string mailContent, string to, string attach)
        {
            string sHost = ConfigurationManager.AppSettings["Mail_Host"].ToString();
            string sUserName = ConfigurationManager.AppSettings["Mail_user"].ToString();
            string sPwd = ConfigurationManager.AppSettings["Mail_pwd"].ToString();
            string sFrom = ConfigurationManager.AppSettings["Mail_From"].ToString();


            //System.Web.Mail.MailMessage objMailMessage = new System.Web.Mail.MailMessage();
            //objMailMessage.From = sFrom;
            //objMailMessage.To = to;
            //objMailMessage.Subject = mailTitle;
            //objMailMessage.Body = mailContent;

            ////基本权限 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            ////用户名 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sUserName);
            ////密码 
            //objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sPwd);
            ////SMTP地址 
            //SmtpMail.SmtpServer = sHost;
            ////开始发送邮件 
            //SmtpMail.Send(objMailMessage);

            MailAddress from = new MailAddress(sFrom);
            MailAddress mto = new MailAddress(to);





            System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage(from, mto);

            //Attachment att = new Attachment(Path.GetFullPath(attach));
            Attachment att = new Attachment(AppDomain.CurrentDomain.BaseDirectory + attach);

            objMailMessage.Priority = System.Net.Mail.MailPriority.High;
            objMailMessage.IsBodyHtml = true;

            objMailMessage.Subject = mailTitle;
            objMailMessage.Body = mailContent;
            objMailMessage.Attachments.Add(att);

            //objMailMessage.

            SmtpClient client = new SmtpClient(sHost);
            client.UseDefaultCredentials = true;
            client.Credentials = new NetworkCredential(sUserName, sPwd);
            client.Send(objMailMessage);
        }


        static List<int> m_lstDateColumnIndex = new List<int>();
        public static void ExportExcel(DataTable dtData, OneSoft.Web.UI.WebControls.SGridView sgvData, string strHead, string strFoot, int iColLen)
        {
            if (sgvData == null || dtData == null)
            {
                return;
            }
            Dictionary<string, string> lst = new Dictionary<string, string>();
            for (int i = 0; i < sgvData.Columns.Count; i++)
            {
                if (sgvData.Columns[i] is BoundField)
                {
                    lst.Add(((System.Web.UI.WebControls.BoundField)(sgvData.Columns[i])).DataField, ((System.Web.UI.WebControls.BoundField)(sgvData.Columns[i])).HeaderText);
                }
            }
            string[] strs = lst.Keys.ToArray();
            DataTable dtTemp = dtData.DefaultView.ToTable(true, strs);
            foreach (DataColumn item in dtTemp.Columns)
            {
                item.ColumnName = lst[item.ColumnName];
            }

            System.Web.UI.WebControls.DataGrid dgExport = null;
            // 当前对话
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            // IO用于导出并返回excel文件
            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;

            if (dtTemp != null)
            {
                // 设置编码和附件格式               

                curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
                curContext.Response.Charset = "";
                curContext.Response.ContentEncoding = System.Text.Encoding.Unicode;
                //curContext.Response.ContentType = ".xls";
                curContext.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 

                byte[] rgByteLeader = new byte[] { 0xFF, 0xFE };
                curContext.Response.BinaryWrite(rgByteLeader);
                // 导出excel文件
                System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
                strWriter = new System.IO.StringWriter(myCItrad);
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

                // 为了解决dgData中可能进行了分页的情况，需要重新定义一个无分页的DataGrid
                dgExport = new System.Web.UI.WebControls.DataGrid();
                dgExport.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(dgExport_ItemDataBound);
                dgExport.DataSource = dtTemp.DefaultView;
                //dgExport.AllowPaging = false;
                dgExport.DataBind();

                // 返回客户端
                dgExport.RenderControl(htmlWriter);

                string strOutput = "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">";
                strOutput += strHead;
                strOutput += "<tr><td colspan=\"" + iColLen.ToString() + "\">";
                strOutput += strWriter.ToString();
                strOutput += "</td></tr>";
                strOutput += strFoot;
                strOutput += "</table>";
                curContext.Response.Write(strOutput);

                //curContext.Response.Write(strWriter.ToString()+strFoot);
                curContext.Response.End();
            }
        }

        public static void ExportExcel(DataTable dt, OneSoft.Web.UI.WebControls.SGridView sgvData)
        {
            // 当前对话
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            // IO用于导出并返回excel文件
            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;
            if (dt != null)
            {
                // 设置编码和附件格式               
                curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
                curContext.Response.Charset = "";
                curContext.Response.ContentEncoding = System.Text.Encoding.Unicode;
                //curContext.Response.ContentType = ".xls";
                curContext.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 

                byte[] rgByteLeader = new byte[] { 0xFF, 0xFE };
                curContext.Response.BinaryWrite(rgByteLeader);
                // 导出excel文件
                System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
                strWriter = new System.IO.StringWriter(myCItrad);
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

                if (dt.Rows.Count == 0)
                {
                    #region 空表头显示
                    dt.Rows.Add(dt.NewRow());
                    dt.AcceptChanges();
                    sgvData.DataSource = dt;
                    sgvData.DataBind();
                    if (sgvData.Rows.Count > 0)
                    {
                        sgvData.Rows[0].Cells[0].Text = "";
                        sgvData.Rows[0].Style.Add(HtmlTextWriterStyle.Display, "none");
                    }
                    #endregion
                }
                else
                {
                    sgvData.DataSource = dt.DefaultView;
                    //dgExport.AllowPaging = false;
                    sgvData.DataBind();
                }

                // 返回客户端
                sgvData.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }
        }

        /// <summary>
        /// 导出excel
        /// </summary>
        /// <param name="dtData"></param>
        /// <param name="sgvData"></param>
        /// <param name="dText"></param>
        public static void ExportExcel(DataTable dtData, OneSoft.Web.UI.WebControls.SGridView sgvData, Dictionary<string, SortedList> dText)
        {
            Regex r = new Regex(@"^[0-9]{1,1000}$");
            DataTable dtTemp = new DataTable();
            m_lstDateColumnIndex.Clear();
            int exCol = 0;
            for (int i = 0; i < sgvData.Columns.Count; i++)
            {
                try
                {
                    DataColumn dc = new DataColumn();
                    if (sgvData.Columns[i] is BoundField)
                    {
                        dc.ColumnName = ((System.Web.UI.WebControls.BoundField)(sgvData.Columns[i])).HeaderText;
                        if (dc.ColumnName.Contains("日") || (dc.ColumnName.Contains("时间") && !dc.ColumnName.Contains("总时间") && !dc.ColumnName.Contains("服务时间") && !dc.ColumnName.Contains("旅程时间") && !dc.ColumnName.Contains("等候时间") && !dc.ColumnName.Contains("响应时间")))
                        {
                            m_lstDateColumnIndex.Add(i - exCol);
                        }
                        //dc.DataType = typeof(System.String);
                        dc.Caption = ((System.Web.UI.WebControls.BoundField)(sgvData.Columns[i])).DataField;
                        dtTemp.Columns.Add(dc);
                    }
                    else
                    {
                        exCol++;
                    }
                }
                catch { }
            }
            for (int i = 0; i < dtData.Rows.Count; i++)
            {
                DataRow dr = dtTemp.NewRow();
                for (int j = 0; j < dtTemp.Columns.Count; j++)
                {
                    if (dText != null && dText.Keys.Contains<string>(dtTemp.Columns[j].Caption))
                    {
                        SortedList slTemp = dText[dtTemp.Columns[j].Caption];
                        string sValue = dtData.Rows[i][dtTemp.Columns[j].Caption].ToString();
                        if (slTemp[sValue] == DBNull.Value || slTemp[sValue] == null || slTemp[sValue].ToString().Trim() == "")
                        {
                            dr[j] = "";
                        }
                        else
                        {


                            dr[j] = slTemp[sValue].ToString();

                        }
                    }
                    else
                    {
                        dr[j] = dtData.Rows[i][dtTemp.Columns[j].Caption].ToString().Replace(">", "&gt;").Replace("<", "&lt;");
                    }
                    if (r.IsMatch(dr[j].ToString()) && dr[j].ToString().StartsWith("0") && dr[j].ToString().Length > 1)
                    {
                        dr[j] = dr[j].ToString() + "&nbsp;";
                    }


                }
                dtTemp.Rows.Add(dr);
            }


            System.Web.UI.WebControls.DataGrid dgExport = null;
            // 当前对话
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            // IO用于导出并返回excel文件
            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;

            if (dtTemp != null)
            {
                // 设置编码和附件格式               

                curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
                curContext.Response.Charset = "";
                curContext.Response.ContentEncoding = System.Text.Encoding.Unicode;
                //curContext.Response.ContentType = ".xls";
                curContext.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 

                byte[] rgByteLeader = new byte[] { 0xFF, 0xFE };
                curContext.Response.BinaryWrite(rgByteLeader);
                // 导出excel文件
                System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
                strWriter = new System.IO.StringWriter(myCItrad);
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

                // 为了解决dgData中可能进行了分页的情况，需要重新定义一个无分页的DataGrid
                dgExport = new System.Web.UI.WebControls.DataGrid();
                dgExport.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(dgExport_ItemDataBound);
                dgExport.DataSource = dtTemp.DefaultView;
                //dgExport.AllowPaging = false;
                dgExport.DataBind();

                // 返回客户端
                dgExport.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }
        }

        static void dgExport_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //将整个datagrid都格式化为文本格式

                //获取显示列的数量可以从数据源那里进行获取
                //比如绑定DataGrid的数据源是DataSet                   
                //datagrid显示列的数量 = ds.tables[0].Columns.Count; 
                //for (int i = 0; i<5; i++)
                //{
                //    e.Item.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                //}

                //对需要格式化的列进行格式化
                //e.Item.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                //e.Item.Cells[2].Attributes.Add("style", "vnd.ms-excel.numberformat::#,##0.00");
                //e.Item.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:￥#,###.00");   
                for (int j = 0; j < m_lstDateColumnIndex.Count; j++)
                {
                    DataRowView drv = (DataRowView)e.Item.DataItem;
                    if (!string.IsNullOrEmpty(drv[m_lstDateColumnIndex[j]].ToString()))
                    {
                        e.Item.Cells[m_lstDateColumnIndex[j]].Text = Convert.ToDateTime(drv[m_lstDateColumnIndex[j]]).ToString("yyyy-MM-dd");
                    }
                    e.Item.Cells[m_lstDateColumnIndex[j]].Attributes.Add("style", "vnd.ms-excel.numberformat:yyyy-mm-dd");

                }
            }
        }

        public static void ExportExcel(System.Web.UI.WebControls.GridView sgvData)
        {
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;

            curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
            curContext.Response.Charset = "";
            curContext.Response.ContentEncoding = System.Text.Encoding.Unicode;
            curContext.Response.ContentType = ".xls";

            byte[] rgByteLeader = new byte[] { 0xFF, 0xFE };
            curContext.Response.BinaryWrite(rgByteLeader);

            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);


            // 返回客户端
            sgvData.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
        }

        public static void ExportExcel(DataTable dtData)
        {
            m_lstDateColumnIndex.Clear();
            Regex r = new Regex(@"^[0-9]{1,1000}$");
            Regex r1 = new Regex(@"^[eE0-9]{1,1000}$");
            for (int j = 0; j < dtData.Columns.Count; j++)
            {
                if (dtData.Columns[j].ColumnName.Contains("日期") || dtData.Columns[j].ColumnName.Contains("时间"))
                {
                    m_lstDateColumnIndex.Add(j);
                }
            }
            for (int i = 0; i < dtData.Rows.Count; i++)
            {
                for (int j = 0; j < dtData.Columns.Count; j++)
                {

                    if (dtData.Rows[i][j].ToString().Trim().ToLower() == "&nbsp;")
                    {
                        dtData.Rows[i][j] = "";
                    }
                    if (r.IsMatch(dtData.Rows[i][j].ToString()) && dtData.Rows[i][j].ToString().StartsWith("0") && dtData.Rows[i][j].ToString().Length > 1)
                    {
                        dtData.Rows[i][j] = dtData.Rows[i][j].ToString() + "&nbsp;";
                    }
                    if (r1.IsMatch(dtData.Rows[i][j].ToString()) && dtData.Rows[i][j].ToString().ToLower().Contains("e")
                        && !dtData.Rows[i][j].ToString().ToLower().StartsWith("e") && !dtData.Rows[i][j].ToString().ToLower().EndsWith("e"))
                    {
                        dtData.Rows[i][j] = dtData.Rows[i][j].ToString() + "&nbsp;";
                    }
                }
            }
            System.Web.UI.WebControls.DataGrid dgExport = new System.Web.UI.WebControls.DataGrid();
            dgExport.ItemDataBound += new DataGridItemEventHandler(dgExport_ItemDataBound);
            dgExport.DataSource = dtData.DefaultView;
            dgExport.AllowPaging = false;
            dgExport.DataBind();

            System.Web.HttpContext curContext = System.Web.HttpContext.Current;

            curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
            curContext.Response.Charset = "";
            curContext.Response.ContentEncoding = System.Text.Encoding.Unicode;
            //curContext.Response.ContentType = ".xls";
            curContext.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 

            byte[] rgByteLeader = new byte[] { 0xFF, 0xFE };
            curContext.Response.BinaryWrite(rgByteLeader);
            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
            System.IO.StringWriter strWriter = new System.IO.StringWriter(myCItrad);
            System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);


            // 返回客户端
            dgExport.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
        }

        /// <summary>
        ///  从Excel读取数据
        /// </summary>
        /// <param name="strFileName">文件名称</param>
        /// <param name="strFileName">Sheet名称</param>
        /// <returns></returns>
        public static DataTable GetDataFromExcel2(HttpPostedFile postFile, ref string errorMsg, string Order)
        {
            if (String.IsNullOrEmpty(postFile.FileName))
            {
                errorMsg = Message.ChooseFile;
                return null;
            }
            if (!(postFile.FileName.ToUpper().EndsWith(".XLS") || postFile.FileName.ToUpper().EndsWith(".XLSX")))
            {
                errorMsg = Message.ChooseExcelFile;
                return null;
            }
            else if (postFile.FileName.ToUpper().EndsWith(".XLSX"))
            {
                errorMsg = Message.ChooseXLSFile;
                return null;
            }
            int index = -1;
            int nMaxLength = int.Parse(ConfigurationManager.AppSettings["UploadFileMaxLenth"].ToString());
            if (postFile.ContentLength >= nMaxLength * 1024 * 1024)
            {
                errorMsg = String.Format(Message.FileCannotBiggerThen4M, nMaxLength.ToString());
                return null;
            }

            string[] sTemp = postFile.FileName.Split('\\');

            postFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);

            string strConn = "";
            if (postFile.FileName.ToUpper().EndsWith(".XLS"))
            {
                strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1] + ";" +
                     "Extended Properties='Excel 8.0;IMEX=1'";
            }
            else
            {
                strConn = "Provider=Microsoft.ACE.OLEDB.12.0" +
                     "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1] + ";" +
                     "Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
            }
            OleDbConnection objConn = new OleDbConnection(strConn);
            objConn.Open();
            DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, null });

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["TABLE_NAME"].ToString().Replace("'","") == Order + "$")
                {
                    index = i;
                }
            }
            if (index == -1)
            {
                errorMsg = "没有此页签";
                objConn.Close();
                File.Delete(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);
                return null;
            }
            OleDbDataAdapter ExcelDA = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", dt.Rows[index]["TABLE_NAME"].ToString()), strConn);


            DataSet ExcelDs = new DataSet();
            try
            {
                ExcelDA.Fill(ExcelDs, "ExcelInfo");
            }
            catch
            {
                //errorMsg = Message.ExcelError;
                //return null;
            }
            finally
            {
                objConn.Close();
                File.Delete(System.Web.HttpContext.Current.Server.MapPath("/UpLoadFile/TempFile/") + sTemp[sTemp.Length - 1]);
            }

            return ExcelDs.Tables[0];
        }

        public static string GetUnicodeSubString(string str, int len, string p_TailString)
        {
            string result = string.Empty;// 最终返回的结果
            int byteLen = System.Text.Encoding.Default.GetByteCount(str);// 单字节字符长度
            int charLen = str.Length;// 把字符平等对待时的字符串长度
            int byteCount = 0;// 记录读取进度
            int pos = 0;// 记录截取位置
            if (byteLen > len)
            {
                for (int i = 0; i < charLen; i++)
                {
                    if (Convert.ToInt32(str.ToCharArray()[i]) > 255)// 按中文字符计算加2
                        byteCount += 2;
                    else// 按英文字符计算加1
                        byteCount += 1;
                    if (byteCount > len)// 超出时只记下上一个有效位置
                    {
                        pos = i;
                        break;
                    }
                    else if (byteCount == len)// 记下当前位置
                    {
                        pos = i + 1;
                        break;
                    }
                }

                if (pos >= 0)
                    result = str.Substring(0, pos) + p_TailString;
            }
            else
                result = str;

            return result;
        }

        /// <summary>
        /// 取指定长度的字符串
        /// </summary>
        /// <param name="p_SrcString">要检查的字符串</param>
        /// <param name="p_StartIndex">起始位置</param>
        /// <param name="p_Length">指定长度</param>
        /// <param name="p_TailString">用于替换的字符串</param>
        /// <returns>截取后的字符串</returns>
        public static string GetSubString(string p_SrcString, int p_StartIndex, int p_Length, string p_TailString)
        {
            string myResult = p_SrcString;

            Byte[] bComments = Encoding.UTF8.GetBytes(p_SrcString);
            foreach (char c in Encoding.UTF8.GetChars(bComments))
            {    //当是日文或韩文时(注:中文的范围:\u4e00 - \u9fa5, 日文在\u0800 - \u4e00, 韩文为\xAC00-\xD7A3)
                if ((c > '\u0800' && c < '\u4e00') || (c > '\xAC00' && c < '\xD7A3'))
                {
                    //if (System.Text.RegularExpressions.Regex.IsMatch(p_SrcString, "[\u0800-\u4e00]+") || System.Text.RegularExpressions.Regex.IsMatch(p_SrcString, "[\xAC00-\xD7A3]+"))
                    //当截取的起始位置超出字段串长度时
                    if (p_StartIndex >= p_SrcString.Length)
                    {
                        return "";
                    }
                    else
                    {
                        return p_SrcString.Substring(p_StartIndex,
                                                       ((p_Length + p_StartIndex) > p_SrcString.Length) ? (p_SrcString.Length - p_StartIndex) : p_Length);
                    }
                }
            }


            if (p_Length >= 0)
            {
                byte[] bsSrcString = Encoding.Default.GetBytes(p_SrcString);

                //当字符串长度大于起始位置
                if (bsSrcString.Length > p_StartIndex)
                {
                    int p_EndIndex = bsSrcString.Length;

                    //当要截取的长度在字符串的有效长度范围内
                    if (bsSrcString.Length > (p_StartIndex + p_Length))
                    {
                        p_EndIndex = p_Length + p_StartIndex;
                    }
                    else
                    {   //当不在有效范围内时,只取到字符串的结尾

                        p_Length = bsSrcString.Length - p_StartIndex;
                        p_TailString = "";
                    }



                    int nRealLength = p_Length;
                    int[] anResultFlag = new int[p_Length];
                    byte[] bsResult = null;

                    int nFlag = 0;
                    for (int i = p_StartIndex; i < p_EndIndex; i++)
                    {

                        if (bsSrcString[i] > 127)
                        {
                            nFlag++;
                            if (nFlag == 3)
                            {
                                nFlag = 1;
                            }
                        }
                        else
                        {
                            nFlag = 0;
                        }

                        anResultFlag[i] = nFlag;
                    }

                    if ((bsSrcString[p_EndIndex - 1] > 127) && (anResultFlag[p_Length - 1] == 1))
                    {
                        nRealLength = p_Length + 1;
                    }

                    bsResult = new byte[nRealLength];

                    Array.Copy(bsSrcString, p_StartIndex, bsResult, 0, nRealLength);

                    myResult = Encoding.Default.GetString(bsResult);

                    myResult = myResult + p_TailString;
                }
            }

            return myResult;
        }

        /// <summary>
        /// 返回字符串真实长度, 1个汉字长度为2
        /// </summary>
        /// <returns>字符长度</returns>
        public static int GetStringLength(string str)
        {
            return Encoding.Default.GetBytes(str).Length;
        }

        #region 汉字转拼音

        private static Hashtable _ht;
        public static string ToPinYin(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return string.Empty;
            }
            if (_ht == null)
                _ht = GetPinyinHash();
            return GetPinYin(s);
        }
        private static string g(int num)
        {
            if (num < -20319 || num > -10247) return "";
            while (!_ht.ContainsKey(num)) num--;
            return _ht[num].ToString();
        }
        private static string GetPinYin(string hz)
        {
            byte[] b = System.Text.Encoding.Default.GetBytes(hz);
            int p;
            StringBuilder ret = new StringBuilder();
            for (int i = 0; i < b.Length; i++)
            {
                p = (int)b[i];
                if (p > 160)
                {
                    p = p * 256 + b[++i] - 65536;
                    ret.Append(g(p));
                }
                else
                    ret.Append((char)p);
            }
            return ret.ToString();
        }
        private static Hashtable GetPinyinHash()
        {
            _ht = new Hashtable();
            _ht.Add(-20319, "a");
            _ht.Add(-20317, "ai");
            _ht.Add(-20304, "an");
            _ht.Add(-20295, "ang");
            _ht.Add(-20292, "ao");
            _ht.Add(-20283, "ba");
            _ht.Add(-20265, "bai");
            _ht.Add(-20257, "ban");
            _ht.Add(-20242, "bang");
            _ht.Add(-20230, "bao");
            _ht.Add(-20051, "bei");
            _ht.Add(-20036, "ben");
            _ht.Add(-20032, "beng");
            _ht.Add(-20026, "bi");
            _ht.Add(-20002, "bian");
            _ht.Add(-19990, "biao");
            _ht.Add(-19986, "bie");
            _ht.Add(-19982, "bin");
            _ht.Add(-19976, "bing");
            _ht.Add(-19805, "bo");
            _ht.Add(-19784, "bu");
            _ht.Add(-19775, "ca");
            _ht.Add(-19774, "cai");
            _ht.Add(-19763, "can");
            _ht.Add(-19756, "cang");
            _ht.Add(-19751, "cao");
            _ht.Add(-19746, "ce");
            _ht.Add(-19741, "ceng");
            _ht.Add(-19739, "cha");
            _ht.Add(-19728, "chai");
            _ht.Add(-19725, "chan");
            _ht.Add(-19715, "chang");
            _ht.Add(-19540, "chao");
            _ht.Add(-19531, "che");
            _ht.Add(-19525, "chen");
            _ht.Add(-19515, "cheng");
            _ht.Add(-19500, "chi");
            _ht.Add(-19484, "chong");
            _ht.Add(-19479, "chou");
            _ht.Add(-19467, "chu");
            _ht.Add(-19289, "chuai");
            _ht.Add(-19288, "chuan");
            _ht.Add(-19281, "chuang");
            _ht.Add(-19275, "chui");
            _ht.Add(-19270, "chun");
            _ht.Add(-19263, "chuo");
            _ht.Add(-19261, "ci");
            _ht.Add(-19249, "cong");
            _ht.Add(-19243, "cou");
            _ht.Add(-19242, "cu");
            _ht.Add(-19238, "cuan");
            _ht.Add(-19235, "cui");
            _ht.Add(-19227, "cun");
            _ht.Add(-19224, "cuo");
            _ht.Add(-19218, "da");
            _ht.Add(-19212, "dai");
            _ht.Add(-19038, "dan");
            _ht.Add(-19023, "dang");
            _ht.Add(-19018, "dao");
            _ht.Add(-19006, "de");
            _ht.Add(-19003, "deng");
            _ht.Add(-18996, "di");
            _ht.Add(-18977, "dian");
            _ht.Add(-18961, "diao");
            _ht.Add(-18952, "die");
            _ht.Add(-18783, "ding");
            _ht.Add(-18774, "diu");
            _ht.Add(-18773, "dong");
            _ht.Add(-18763, "dou");
            _ht.Add(-18756, "du");
            _ht.Add(-18741, "duan");
            _ht.Add(-18735, "dui");
            _ht.Add(-18731, "dun");
            _ht.Add(-18722, "duo");
            _ht.Add(-18710, "e");
            _ht.Add(-18697, "en");
            _ht.Add(-18696, "er");
            _ht.Add(-18526, "fa");
            _ht.Add(-18518, "fan");
            _ht.Add(-18501, "fang");
            _ht.Add(-18490, "fei");
            _ht.Add(-18478, "fen");
            _ht.Add(-18463, "feng");
            _ht.Add(-18448, "fo");
            _ht.Add(-18447, "fou");
            _ht.Add(-18446, "fu");
            _ht.Add(-18239, "ga");
            _ht.Add(-18237, "gai");
            _ht.Add(-18231, "gan");
            _ht.Add(-18220, "gang");
            _ht.Add(-18211, "gao");
            _ht.Add(-18201, "ge");
            _ht.Add(-18184, "gei");
            _ht.Add(-18183, "gen");
            _ht.Add(-18181, "geng");
            _ht.Add(-18012, "gong");
            _ht.Add(-17997, "gou");
            _ht.Add(-17988, "gu");
            _ht.Add(-17970, "gua");
            _ht.Add(-17964, "guai");
            _ht.Add(-17961, "guan");
            _ht.Add(-17950, "guang");
            _ht.Add(-17947, "gui");
            _ht.Add(-17931, "gun");
            _ht.Add(-17928, "guo");
            _ht.Add(-17922, "ha");
            _ht.Add(-17759, "hai");
            _ht.Add(-17752, "han");
            _ht.Add(-17733, "hang");
            _ht.Add(-17730, "hao");
            _ht.Add(-17721, "he");
            _ht.Add(-17703, "hei");
            _ht.Add(-17701, "hen");
            _ht.Add(-17697, "heng");
            _ht.Add(-17692, "hong");
            _ht.Add(-17683, "hou");
            _ht.Add(-17676, "hu");
            _ht.Add(-17496, "hua");
            _ht.Add(-17487, "huai");
            _ht.Add(-17482, "huan");
            _ht.Add(-17468, "huang");
            _ht.Add(-17454, "hui");
            _ht.Add(-17433, "hun");
            _ht.Add(-17427, "huo");
            _ht.Add(-17417, "ji");
            _ht.Add(-17202, "jia");
            _ht.Add(-17185, "jian");
            _ht.Add(-16983, "jiang");
            _ht.Add(-16970, "jiao");
            _ht.Add(-16942, "jie");
            _ht.Add(-16915, "jin");
            _ht.Add(-16733, "jing");
            _ht.Add(-16708, "jiong");
            _ht.Add(-16706, "jiu");
            _ht.Add(-16689, "ju");
            _ht.Add(-16664, "juan");
            _ht.Add(-16657, "jue");
            _ht.Add(-16647, "jun");
            _ht.Add(-16474, "ka");
            _ht.Add(-16470, "kai");
            _ht.Add(-16465, "kan");
            _ht.Add(-16459, "kang");
            _ht.Add(-16452, "kao");
            _ht.Add(-16448, "ke");
            _ht.Add(-16433, "ken");
            _ht.Add(-16429, "keng");
            _ht.Add(-16427, "kong");
            _ht.Add(-16423, "kou");
            _ht.Add(-16419, "ku");
            _ht.Add(-16412, "kua");
            _ht.Add(-16407, "kuai");
            _ht.Add(-16403, "kuan");
            _ht.Add(-16401, "kuang");
            _ht.Add(-16393, "kui");
            _ht.Add(-16220, "kun");
            _ht.Add(-16216, "kuo");
            _ht.Add(-16212, "la");
            _ht.Add(-16205, "lai");
            _ht.Add(-16202, "lan");
            _ht.Add(-16187, "lang");
            _ht.Add(-16180, "lao");
            _ht.Add(-16171, "le");
            _ht.Add(-16169, "lei");
            _ht.Add(-16158, "leng");
            _ht.Add(-16155, "li");
            _ht.Add(-15959, "lia");
            _ht.Add(-15958, "lian");
            _ht.Add(-15944, "liang");
            _ht.Add(-15933, "liao");
            _ht.Add(-15920, "lie");
            _ht.Add(-15915, "lin");
            _ht.Add(-15903, "ling");
            _ht.Add(-15889, "liu");
            _ht.Add(-15878, "long");
            _ht.Add(-15707, "lou");
            _ht.Add(-15701, "lu");
            _ht.Add(-15681, "lv");
            _ht.Add(-15667, "luan");
            _ht.Add(-15661, "lue");
            _ht.Add(-15659, "lun");
            _ht.Add(-15652, "luo");
            _ht.Add(-15640, "ma");
            _ht.Add(-15631, "mai");
            _ht.Add(-15625, "man");
            _ht.Add(-15454, "mang");
            _ht.Add(-15448, "mao");
            _ht.Add(-15436, "me");
            _ht.Add(-15435, "mei");
            _ht.Add(-15419, "men");
            _ht.Add(-15416, "meng");
            _ht.Add(-15408, "mi");
            _ht.Add(-15394, "mian");
            _ht.Add(-15385, "miao");
            _ht.Add(-15377, "mie");
            _ht.Add(-15375, "min");
            _ht.Add(-15369, "ming");
            _ht.Add(-15363, "miu");
            _ht.Add(-15362, "mo");
            _ht.Add(-15183, "mou");
            _ht.Add(-15180, "mu");
            _ht.Add(-15165, "na");
            _ht.Add(-15158, "nai");
            _ht.Add(-15153, "nan");
            _ht.Add(-15150, "nang");
            _ht.Add(-15149, "nao");
            _ht.Add(-15144, "ne");
            _ht.Add(-15143, "nei");
            _ht.Add(-15141, "nen");
            _ht.Add(-15140, "neng");
            _ht.Add(-15139, "ni");
            _ht.Add(-15128, "nian");
            _ht.Add(-15121, "niang");
            _ht.Add(-15119, "niao");
            _ht.Add(-15117, "nie");
            _ht.Add(-15110, "nin");
            _ht.Add(-15109, "ning");
            _ht.Add(-14941, "niu");
            _ht.Add(-14937, "nong");
            _ht.Add(-14933, "nu");
            _ht.Add(-14930, "nv");
            _ht.Add(-14929, "nuan");
            _ht.Add(-14928, "nue");
            _ht.Add(-14926, "nuo");
            _ht.Add(-14922, "o");
            _ht.Add(-14921, "ou");
            _ht.Add(-14914, "pa");
            _ht.Add(-14908, "pai");
            _ht.Add(-14902, "pan");
            _ht.Add(-14894, "pang");
            _ht.Add(-14889, "pao");
            _ht.Add(-14882, "pei");
            _ht.Add(-14873, "pen");
            _ht.Add(-14871, "peng");
            _ht.Add(-14857, "pi");
            _ht.Add(-14678, "pian");
            _ht.Add(-14674, "piao");
            _ht.Add(-14670, "pie");
            _ht.Add(-14668, "pin");
            _ht.Add(-14663, "ping");
            _ht.Add(-14654, "po");
            _ht.Add(-14645, "pu");
            _ht.Add(-14630, "qi");
            _ht.Add(-14594, "qia");
            _ht.Add(-14429, "qian");
            _ht.Add(-14407, "qiang");
            _ht.Add(-14399, "qiao");
            _ht.Add(-14384, "qie");
            _ht.Add(-14379, "qin");
            _ht.Add(-14368, "qing");
            _ht.Add(-14355, "qiong");
            _ht.Add(-14353, "qiu");
            _ht.Add(-14345, "qu");
            _ht.Add(-14170, "quan");
            _ht.Add(-14159, "que");
            _ht.Add(-14151, "qun");
            _ht.Add(-14149, "ran");
            _ht.Add(-14145, "rang");
            _ht.Add(-14140, "rao");
            _ht.Add(-14137, "re");
            _ht.Add(-14135, "ren");
            _ht.Add(-14125, "reng");
            _ht.Add(-14123, "ri");
            _ht.Add(-14122, "rong");
            _ht.Add(-14112, "rou");
            _ht.Add(-14109, "ru");
            _ht.Add(-14099, "ruan");
            _ht.Add(-14097, "rui");
            _ht.Add(-14094, "run");
            _ht.Add(-14092, "ruo");
            _ht.Add(-14090, "sa");
            _ht.Add(-14087, "sai");
            _ht.Add(-14083, "san");
            _ht.Add(-13917, "sang");
            _ht.Add(-13914, "sao");
            _ht.Add(-13910, "se");
            _ht.Add(-13907, "sen");
            _ht.Add(-13906, "seng");
            _ht.Add(-13905, "sha");
            _ht.Add(-13896, "shai");
            _ht.Add(-13894, "shan");
            _ht.Add(-13878, "shang");
            _ht.Add(-13870, "shao");
            _ht.Add(-13859, "she");
            _ht.Add(-13847, "shen");
            _ht.Add(-13831, "sheng");
            _ht.Add(-13658, "shi");
            _ht.Add(-13611, "shou");
            _ht.Add(-13601, "shu");
            _ht.Add(-13406, "shua");
            _ht.Add(-13404, "shuai");
            _ht.Add(-13400, "shuan");
            _ht.Add(-13398, "shuang");
            _ht.Add(-13395, "shui");
            _ht.Add(-13391, "shun");
            _ht.Add(-13387, "shuo");
            _ht.Add(-13383, "si");
            _ht.Add(-13367, "song");
            _ht.Add(-13359, "sou");
            _ht.Add(-13356, "su");
            _ht.Add(-13343, "suan");
            _ht.Add(-13340, "sui");
            _ht.Add(-13329, "sun");
            _ht.Add(-13326, "suo");
            _ht.Add(-13318, "ta");
            _ht.Add(-13147, "tai");
            _ht.Add(-13138, "tan");
            _ht.Add(-13120, "tang");
            _ht.Add(-13107, "tao");
            _ht.Add(-13096, "te");
            _ht.Add(-13095, "teng");
            _ht.Add(-13091, "ti");
            _ht.Add(-13076, "tian");
            _ht.Add(-13068, "tiao");
            _ht.Add(-13063, "tie");
            _ht.Add(-13060, "ting");
            _ht.Add(-12888, "tong");
            _ht.Add(-12875, "tou");
            _ht.Add(-12871, "tu");
            _ht.Add(-12860, "tuan");
            _ht.Add(-12858, "tui");
            _ht.Add(-12852, "tun");
            _ht.Add(-12849, "tuo");
            _ht.Add(-12838, "wa");
            _ht.Add(-12831, "wai");
            _ht.Add(-12829, "wan");
            _ht.Add(-12812, "wang");
            _ht.Add(-12802, "wei");
            _ht.Add(-12607, "wen");
            _ht.Add(-12597, "weng");
            _ht.Add(-12594, "wo");
            _ht.Add(-12585, "wu");
            _ht.Add(-12556, "xi");
            _ht.Add(-12359, "xia");
            _ht.Add(-12346, "xian");
            _ht.Add(-12320, "xiang");
            _ht.Add(-12300, "xiao");
            _ht.Add(-12120, "xie");
            _ht.Add(-12099, "xin");
            _ht.Add(-12089, "xing");
            _ht.Add(-12074, "xiong");
            _ht.Add(-12067, "xiu");
            _ht.Add(-12058, "xu");
            _ht.Add(-12039, "xuan");
            _ht.Add(-11867, "xue");
            _ht.Add(-11861, "xun");
            _ht.Add(-11847, "ya");
            _ht.Add(-11831, "yan");
            _ht.Add(-11798, "yang");
            _ht.Add(-11781, "yao");
            _ht.Add(-11604, "ye");
            _ht.Add(-11589, "yi");
            _ht.Add(-11536, "yin");
            _ht.Add(-11358, "ying");
            _ht.Add(-11340, "yo");
            _ht.Add(-11339, "yong");
            _ht.Add(-11324, "you");
            _ht.Add(-11303, "yu");
            _ht.Add(-11097, "yuan");
            _ht.Add(-11077, "yue");
            _ht.Add(-11067, "yun");
            _ht.Add(-11055, "za");
            _ht.Add(-11052, "zai");
            _ht.Add(-11045, "zan");
            _ht.Add(-11041, "zang");
            _ht.Add(-11038, "zao");
            _ht.Add(-11024, "ze");
            _ht.Add(-11020, "zei");
            _ht.Add(-11019, "zen");
            _ht.Add(-11018, "zeng");
            _ht.Add(-11014, "zha");
            _ht.Add(-10838, "zhai");
            _ht.Add(-10832, "zhan");
            _ht.Add(-10815, "zhang");
            _ht.Add(-10800, "zhao");
            _ht.Add(-10790, "zhe");
            _ht.Add(-10780, "zhen");
            _ht.Add(-10764, "zheng");
            _ht.Add(-10587, "zhi");
            _ht.Add(-10544, "zhong");
            _ht.Add(-10533, "zhou");
            _ht.Add(-10519, "zhu");
            _ht.Add(-10331, "zhua");
            _ht.Add(-10329, "zhuai");
            _ht.Add(-10328, "zhuan");
            _ht.Add(-10322, "zhuang");
            _ht.Add(-10315, "zhui");
            _ht.Add(-10309, "zhun");
            _ht.Add(-10307, "zhuo");
            _ht.Add(-10296, "zi");
            _ht.Add(-10281, "zong");
            _ht.Add(-10274, "zou");
            _ht.Add(-10270, "zu");
            _ht.Add(-10262, "zuan");
            _ht.Add(-10260, "zui");
            _ht.Add(-10256, "zun");
            _ht.Add(-10254, "zuo");
            _ht.Add(-10247, "zz");
            return _ht;
        }

        /// <summary> 
        /// 在指定的字符串列表CnStr中检索符合拼音索引字符串 
        /// </summary> 
        /// <param name="CnStr">汉字字符串</param> 
        /// <returns>相对应的汉语拼音首字母串</returns> 
        public static string GetSpellCode(string CnStr)
        {
            if (string.IsNullOrEmpty(CnStr))
            {
                return string.Empty;
            }
            string strTemp = "";
            int iLen = CnStr.Length;
            int i = 0;

            for (i = 0; i <= iLen - 1; i++)
            {
                strTemp += GetCharSpellCode(CnStr.Substring(i, 1));
            }

            return strTemp;
        }


        /// <summary> 
        /// 得到一个汉字的拼音第一个字母，如果是一个英文字母则直接返回大写字母 
        /// </summary> 
        /// <param name="CnChar">单个汉字</param> 
        /// <returns>单个大写字母</returns> 
        private static string GetCharSpellCode(string CnChar)
        {
            long iCnChar;

            byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);

            //如果是字母，则直接返回 
            if (ZW.Length == 1)
            {
                return CnChar.ToUpper();
            }
            else
            {
                // get the array of byte from the single char 
                int i1 = (short)(ZW[0]);
                int i2 = (short)(ZW[1]);
                iCnChar = i1 * 256 + i2;
            }

            //expresstion 
            //table of the constant list 
            // 'A'; //45217..45252 
            // 'B'; //45253..45760 
            // 'C'; //45761..46317 
            // 'D'; //46318..46825 
            // 'E'; //46826..47009 
            // 'F'; //47010..47296 
            // 'G'; //47297..47613 

            // 'H'; //47614..48118 
            // 'J'; //48119..49061 
            // 'K'; //49062..49323 
            // 'L'; //49324..49895 
            // 'M'; //49896..50370 
            // 'N'; //50371..50613 
            // 'O'; //50614..50621 
            // 'P'; //50622..50905 
            // 'Q'; //50906..51386 

            // 'R'; //51387..51445 
            // 'S'; //51446..52217 
            // 'T'; //52218..52697 
            //没有U,V 
            // 'W'; //52698..52979 
            // 'X'; //52980..53640 
            // 'Y'; //53689..54480 
            // 'Z'; //54481..55289 

            // iCnChar match the constant 
            if ((iCnChar >= 45217) && (iCnChar <= 45252))
            {
                return "A";
            }
            else if ((iCnChar >= 45253) && (iCnChar <= 45760))
            {
                return "B";
            }
            else if ((iCnChar >= 45761) && (iCnChar <= 46317))
            {
                return "C";
            }
            else if ((iCnChar >= 46318) && (iCnChar <= 46825))
            {
                return "D";
            }
            else if ((iCnChar >= 46826) && (iCnChar <= 47009))
            {
                return "E";
            }
            else if ((iCnChar >= 47010) && (iCnChar <= 47296))
            {
                return "F";
            }
            else if ((iCnChar >= 47297) && (iCnChar <= 47613))
            {
                return "G";
            }
            else if ((iCnChar >= 47614) && (iCnChar <= 48118))
            {
                return "H";
            }
            else if ((iCnChar >= 48119) && (iCnChar <= 49061))
            {
                return "J";
            }
            else if ((iCnChar >= 49062) && (iCnChar <= 49323))
            {
                return "K";
            }
            else if ((iCnChar >= 49324) && (iCnChar <= 49895))
            {
                return "L";
            }
            else if ((iCnChar >= 49896) && (iCnChar <= 50370))
            {
                return "M";
            }

            else if ((iCnChar >= 50371) && (iCnChar <= 50613))
            {
                return "N";
            }
            else if ((iCnChar >= 50614) && (iCnChar <= 50621))
            {
                return "O";
            }
            else if ((iCnChar >= 50622) && (iCnChar <= 50905))
            {
                return "P";
            }
            else if ((iCnChar >= 50906) && (iCnChar <= 51386))
            {
                return "Q";
            }
            else if ((iCnChar >= 51387) && (iCnChar <= 51445))
            {
                return "R";
            }
            else if ((iCnChar >= 51446) && (iCnChar <= 52217))
            {
                return "S";
            }
            else if ((iCnChar >= 52218) && (iCnChar <= 52697))
            {
                return "T";
            }
            else if ((iCnChar >= 52698) && (iCnChar <= 52979))
            {
                return "W";
            }
            else if ((iCnChar >= 52980) && (iCnChar <= 53688))
            {
                return "X";
            }
            else if ((iCnChar >= 53689) && (iCnChar <= 54480))
            {
                return "Y";
            }
            else if ((iCnChar >= 54481) && (iCnChar <= 55289))
            {
                return "Z";
            }
            else return ("?");

        }

        #endregion

        /// <summary>
        /// 检查主健唯一性
        /// </summary>
        /// <param name="value"></param>
        /// <param name="tableName"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        public static string SelEITCingle(string value, string tableName, string field)
        {
            string sReturn = "";
            //object oTemp = DataAccessCommon.SelEITCingleObject(value, tableName, field);
            WhereBuilder wb = new WhereBuilder();
            wb.AddAndCondition(field, value);
            object oTemp = DataAccessCommon.SelectSingleObject("status", tableName, wb);
            if (oTemp != null)
            {
                sReturn = oTemp.ToString();
            }
            return sReturn;
        }

        /// <summary>
        /// 根据主键(不区分大小写)删除数据
        /// </summary>
        /// <param name="value"></param>
        /// <param name="tableName"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        public static bool Delete(string value, string tableName, string field)
        {
            return DataAccessCommon.Delete(value, field, tableName);
        }

        /// <summary>
        ///  获得指定小数位的字符串（整数不返回小数位）
        /// </summary>
        /// <param name="num">需要格式的数据</param>
        /// <param name="dotLength">小数位数</param>
        /// <returns></returns>
        public static string GetFomatNumber(decimal num, int dotLength)
        {
            if (num.ToString().LastIndexOf(".") > 0 && dotLength > 0)
            {
                return num.ToString().Substring(0, num.ToString().LastIndexOf(".") + dotLength + 1);
            }
            else
            {
                return num.ToString();
            }

        }

        #region GetPagedTable DataTable分页
        /// <summary>
        /// DataTable分页
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="PageIndex">页索引,注意：从0开始</param>
        /// <param name="PageSize">每页大小</param>
        /// <returns></returns>
        public static DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
        {

            DataTable newdt = dt.Copy();
            newdt.Clear();

            int rowbegin = PageIndex * PageSize;
            int rowend = (PageIndex + 1) * PageSize;

            if (rowbegin >= dt.Rows.Count)
                return newdt;

            if (rowend > dt.Rows.Count)
                rowend = dt.Rows.Count;

            for (int i = rowbegin; i <= rowend - 1; i++)
            {
                newdt.ImportRow(dt.Rows[i]);
            }

            return newdt;
        }
        #endregion

        /// <summary>
        /// list转datatable
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static DataTable convert2Table<T>(List<T> list)
        {
            DataTable table = new DataTable();

            if (list.Count > 0)
            {
                PropertyInfo[] properties = list[0].GetType().GetProperties();
                List<string> columns = new List<string>();
                foreach (PropertyInfo pi in properties)
                {
                    table.Columns.Add(pi.Name);
                    columns.Add(pi.Name);
                }
                foreach (T item in list)
                {
                    object[] cells = getValues(columns, item);
                    table.Rows.Add(cells);
                }
            }
            return table;

        }


        private static object[] getValues(List<string> columns, object instance)
        {
            object[] ret = new object[columns.Count];

            for (int n = 0; n < ret.Length; n++)
            {
                try
                {
                    PropertyInfo pi = instance.GetType().GetProperty(columns[n]);
                    object value = pi.GetValue(instance, null);
                    ret[n] = value;
                }
                catch
                {
                    ret[n] = "";
                }
            }
            return ret;
        }

        public static string GetPersonalPartsStorageId()
        {
            string sReturn = "";
            if (ConfigurationManager.AppSettings["PersonalParts_StorageId"] != null)
            {
                sReturn = ConfigurationManager.AppSettings["PersonalParts_StorageId"].ToString();
            }
            return sReturn;
        }

        /// <summary>
        /// 获得ASP仓库
        /// </summary>
        /// <returns></returns>
        public static string GetASPSendPartsStorageId()
        {
            string sReturn = "";
            if (ConfigurationManager.AppSettings["ASPSendParts_StorageId"] != null)
            {
                sReturn = ConfigurationManager.AppSettings["ASPSendParts_StorageId"].ToString();
            }
            return sReturn;
        }

        /// <summary>
        /// 获得ASP仓库通用库位
        /// </summary>
        /// <returns></returns>
        public static string GetASPPersonalStorePosition()
        {
            string sReturn = "";
            if (ConfigurationManager.AppSettings["ASPPersonalStorePosition"] != null)
            {
                sReturn = ConfigurationManager.AppSettings["ASPPersonalStorePosition"].ToString();
            }
            return sReturn;
        }


        public static Int32 StrToInt32(string parm, Int32 defaultvalue)
        {
            Int32 result = defaultvalue;
            Int32.TryParse(parm, out result);
            return result;

        }

        #region  产生随机数
        private static char[] constantChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
        private static char[] constSpecailChar = { '!', '#', '@', '%', '*', '$' };

        /// <summary>
        ///   随机字母
        /// </summary>
        /// <param name="Length"></param>
        /// <returns></returns>
        public static string GenerateRandomString(int length)
        {
            return CenerateRandom(length, constantChar);
        }

        /// <summary>
        ///  获取随机特殊字符
        /// </summary>
        /// <returns></returns>
        public static string GenerateRandomSpecialChar(int length)
        {
            return CenerateRandom(length, constSpecailChar);
        }

        private static string CenerateRandom(int Length, char[] constant)
        {
            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(constant.Length);

            Random rd = new Random(); for (int i = 0; i < Length; i++)

            { newRandom.Append(constant[rd.Next(constant.Length - 1)]); }

            return newRandom.ToString();
        }
        #endregion

        #region 产生随机密码
        /// <summary>
        ///  获取随机密码
        ///  密码规则 2个字母+特殊符+两个字母+特殊符+四位随机数
        /// </summary>
        /// <returns></returns>
        /// <remarks > tina.su modify 2010-8-5</remarks>
        public static string GetRandomPassword()
        {
            string randomStr4 = GenerateRandomString(4);//获取四位随机字母
            string randomSpecialChar = GenerateRandomSpecialChar(2);//获取两位随机特殊符
            string tempPwd = randomStr4.Substring(0, 2) + randomSpecialChar.Substring(0, 1)
                            + randomStr4.Substring(2, 2) + randomSpecialChar.Substring(1, 1);
            Random rnd = new Random();
            int rndNum = rnd.Next(1000, 9999);      //得1000~9999的随机数 
            tempPwd += rndNum.ToString();
            return tempPwd;
        }
        #endregion

        #region 根据设备型号获取其PM对应角色的名称
        /// <summary>
        /// 根据设备型号获取其PM对应角色的名称
        /// </summary>
        /// <param name="equipmentModelID">设备型号</param>
        /// <remarks>author:tina.su 2010-9-3</remarks>
        /// <returns>角色名称</returns>
        public static string GetPMRoleNameByModelid(string equipmentModelID)
        {
            /*****************************************************************
             --每种设备型号设定一个对应的PM角色，比如：3600设定一个角色3600PM.
             -- 规则是： 型号+PM
            *********************************************************************/
            return string.IsNullOrEmpty(equipmentModelID) ? null : equipmentModelID + "PM";
        }
        #endregion

        #region 获取指定日期所处周的一周日期
        /// <summary>
        /// 获取指定日期所处周的一周日期(周日--周六）
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DataTable GetWeekDates(DateTime date)
        {
            DataTable dt = new DataTable();
            DataColumn col1 = new DataColumn("Date", typeof(DateTime));
            DataColumn col2 = new DataColumn("remark");
            dt.Columns.Add(col1);
            dt.Columns.Add(col2);
            int dayofWeek = (int)date.DayOfWeek;
            DateTime sunday = date.AddDays(0 - dayofWeek).Date;

            for (int i = 0; i < 7; i++)
            {
                DataRow row = dt.NewRow();
                DateTime tempDate = sunday.AddDays(i);
                row["Date"] = tempDate;
                row["Remark"] = tempDate.ToString("yyyyy-MM-dd  " + GetChineseWeekDayName(i));
                dt.Rows.Add(row);
            }
            return dt;
        }

        public static string GetChineseWeekDayName(int dayOfweek)
        {
            string result = "";
            switch (dayOfweek)
            {
                case 0:
                    result = "星期日";
                    break;
                case 1:
                    result = "星期一";
                    break;
                case 2:
                    result = "星期二";
                    break;
                case 3:
                    result = "星期三";
                    break;
                case 4:
                    result = "星期四";
                    break;
                case 5:
                    result = "星期五";
                    break;
                case 6:
                    result = "星期六";
                    break;

                default:
                    result = null;
                    break;
            }
            return result;
        }
        #endregion

        #region 判断两个时间段是否有交叉
        /// <summary>
        ///  判断两个时间段是否有交叉
        /// </summary>
        /// <param name="time1Start"></param>
        /// <param name="time1End"></param>
        /// <param name="time2Start1"></param>
        /// <param name="time2End"></param>
        /// <returns></returns>
        public static bool HasTimeConflict(DateTime time1Start, DateTime time1End, DateTime time2Start, DateTime time2End)
        {
            DateTime temp1A = DateTime.MinValue;
            DateTime temp1B = DateTime.MinValue;
            DateTime temp2A = DateTime.MinValue;
            DateTime temp2B = DateTime.MinValue;

            if (time1Start < time2Start)
            {
                temp1A = time1Start;
                temp1B = time1End;
                temp2A = time2Start;
                temp2B = time2End;
            }
            else
            {
                temp1A = time2Start;
                temp1B = time2End;
                temp2A = time1Start;
                temp2B = time1End;
            }
            if (temp2A <= temp1B)
                return true;
            return false;

        }
        #endregion

        #region 获取指定年的第几周的第一天（周日）
        public static DateTime GetSundayOfYear(int year, int weekIndex)
        {
            DateTime firstDayOfYear = Convert.ToDateTime(year + "-01-01");
            int fistDayOfWeek = (int)firstDayOfYear.DayOfWeek;
            DateTime sunday = firstDayOfYear.AddDays((7 * (weekIndex - 1)) - fistDayOfWeek);//一年第几周的星期日
            return sunday;
        }
        #endregion

        /// <summary>
        /// 获得Depuy 初始时间
        /// </summary>
        /// <returns></returns>
        public static DateTime? GetDepuyStartDate()
        {
            string sReturn = "";
            if (ConfigurationManager.AppSettings["Depuy_Initial_Date"] != null)
            {
                sReturn = ConfigurationManager.AppSettings["Depuy_Initial_Date"].ToString();
            }
            return sReturn == "" ? (DateTime?)null : Convert.ToDateTime(sReturn);
        }

        public static bool IsDate(object obj)
        {
            DateTime _value = DateTime.Now;
            if (DateTime.TryParse(obj.ToString(), out _value))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        

        public static int ConvertToInt(object obj)
        {
            int tep = 0;
            Int32.TryParse(obj.ToString(), out tep);
            return tep;
        }

        public static string GetDecimal(object obj,int iLen)
        {
            decimal tep = 0;
            decimal.TryParse(obj.ToString(), out tep);
            return Math.Round(tep,iLen).ToString();
        }

        public static decimal ConvertToDecimal(object obj)
        {
            if (null == obj)
            {
                return 0;
            }
            decimal tep = 0;
            decimal.TryParse(obj.ToString(), out tep);
            return tep;
        }

        public static decimal ConvertToDecimal(object obj, int iLen)
        {
            decimal tep = 0;
            decimal.TryParse(obj.ToString(), out tep);
            return Math.Round(tep, iLen);
        }


        public static string ConvertToDate(object obj)
        {
            DateTime _value = DateTime.Now;
            if (DateTime.TryParse(obj.ToString(), out _value))
            {
                return Convert.ToDateTime(obj.ToString()).ToString("yyyy-MM-dd");
            }
            else
            {
                return "";
            }
        }

        public static string ConvertToDate(object obj,int iAddDay)
        {
            DateTime _value = DateTime.Now;
            if (DateTime.TryParse(obj.ToString(), out _value))
            {
                return Convert.ToDateTime(obj.ToString()).AddDays(iAddDay).ToString("yyyy-MM-dd");
            }
            else
            {
                return "";
            }
        }

        public static string ConvertToMonth(object obj)
        {
            DateTime _value = DateTime.Now;
            if (DateTime.TryParse(obj.ToString(), out _value))
            {
                return Convert.ToDateTime(obj.ToString()).ToString("MM-dd");
            }
            else
            {
                return "";
            }
        }

        public static string ConvertToDate2(object obj)
        {
            DateTime _value = DateTime.Now;
            if (DateTime.TryParse(obj.ToString(), out _value))
            {
                return Convert.ToDateTime(obj.ToString()).ToString("yyyy-MM-dd HH:mm");
            }
            else
            {
                return "";
            }
        }

        public static string GetString(object obj)
        {
            if (obj == null||obj==DBNull.Value)
                return "";
            else
                return obj.ToString().Trim();
        }

        public static string GetOnlyString(object obj)
        {
            if (obj == null)
                return "";
            else
            {
                Regex regex = new Regex("&nbsp;", RegexOptions.IgnoreCase);
                if (regex.IsMatch(obj.ToString()))
                    return "";
                else
                    return obj.ToString();
            }
        }

        public static string GetStatusName(object objStatus)
        {
            string strStatus = CommonMethod.GetString(objStatus);
            string str = "";
            switch (strStatus)
            {
                case "0":
                    str = "删除";
                    break;
                case "1":
                    str = "有效";
                    break;
                case "2":
                    str = "审核中";
                    break;
                case "3":
                    str = "暂存";
                    break;
                case "4":
                    str = "退件";
                    break;
                default:
                    break;
            }
            return str;
        }

        /// <summary>
        /// 取得某TAB下的最大的排序号+1
        /// </summary>
        /// <param name="dtData"></param>
        /// <param name="strlx">4个TAB之一</param>
        /// <param name="strScalar"></param>
        /// <returns></returns>
        public static int GetScalarOrder(DataTable dtData, string strlx, string strScalar)
        {
            DataRow[] rows = dtData.Select(string.Format("BOMTAB='{0}' and MatScalar='{1}'", strlx, strScalar));
            if (rows.Length < 1)
            {
                return 1;
            }
            else
            {
                int i = 0;
                foreach (DataRow item in rows)
                {
                    string str = CommonMethod.GetString(item["HideCode"]);
                    if (str.Length < 3)
                    {
                        continue;
                    }
                    str = str.Substring(str.Length - 3, 3);
                    if (Convert.ToInt32(str) > i)
                    {
                        i = Convert.ToInt32(str);
                    }
                }
                return i + 1;
            }
        }

        public static string GetMatPre(string strMatScalar)
        {
            string str = "";
            switch (strMatScalar)
            {
                case "1": str = "11"; break;
                case "2": str = "44"; break;
                case "3": str = "55"; break;
                case "4": str = "88"; break;
                default:
                    break;
            }
            return str;
        }
    }

    /// <summary>
    /// 汉字转拼音类
    /// by http://www.crazycoder.cn
    /// build Date 20030610
    /// </summary>
    public class CrazyCoderPinyin
    {

        /// <summary>
        /// 定义拼音区编码数组
        /// </summary>
        private static int[] pyValue = new int[]
                {
                -20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,
                -20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,
                -19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,
                -19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,
                -19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,
                -19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,
                -18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,
                -18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,
                -17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,
                -17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,
                -17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,
                -16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,
                -16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,
                -16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,
                -15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,
                -15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,
                -15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,
                -15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-15117,-15110,-15109,
                -14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-14914,-14908,-14902,
                -14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-14668,-14663,-14654,
                -14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-14355,-14353,-14345,
                -14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-14123,-14122,-14112,
                -14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-13914,-13910,-13907,
                -13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-13658,-13611,-13601,
                -13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-13359,-13356,-13343,
                -13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076,
                -13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-12849,-12838,-12831,
                -12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-12346,-12320,-12300,
                -12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-11847,-11831,-11798,
                -11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-11097,-11077,-11067,
                -11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-11014,-10838,-10832,
                -10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,
                -10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-10260,-10256,-10254
                };
        /// <summary>
        /// 定义数组
        /// </summary>
        private static string[] pyName = new string[]
                {
                "A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben",
                "Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can",
                "Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng",
                "Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong",
                "Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De",
                "Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui",
                "Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo",
                "Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong",
                "Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han",
                "Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan",
                "Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing",
                "Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke",
                "Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo",
                "La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang",
                "Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun",
                "Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian",
                "Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang",
                "Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning",
                "Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan",
                "Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po",
                "Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu",
                "Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou",
                "Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen",
                "Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu",
                "Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan",
                "Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian",
                "Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai",
                "Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao",
                "Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang",
                "Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun",
                "Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan",
                "Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan",
                "Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"
                };
        /// <summary>
        /// 汉字转换
        /// by http://www.crazycoder.cn/
        /// </summary>
        /// <param name="hzString"></param>
        /// <returns></returns>
        public static string Convert(string hzString)
        {

            return Convert(hzString, 10);
        }
        /// <summary>
        /// 把汉字转换成拼音(全拼)
        /// by http://www.crazycoder.cn/
        /// </summary>
        /// <param name="hzString">汉字字符串</param>
        /// <returns>转换后的拼音(全拼)字符串</returns>
        public static string Convert(string hzString, int maxLength)
        {

            if (string.IsNullOrEmpty(hzString))
                return null;
            if (maxLength <= 1)
                maxLength = 10;
            hzString = hzString.Trim().Replace(" ", "").Replace("?", "_").Replace("\\", "_").Replace("/", "_").Replace(":", "").Replace("*", "").Replace(">", "").Replace("<", "").Replace("?", "").Replace("|", "").Replace("\"", "'").Replace("(", "_").Replace(")", "_").Replace(";", "_");
            hzString = hzString.Replace("，", ",").Replace("；", "_").Replace("。", "_").Replace("”", "").Replace("“", "").Replace("[", "").Replace("]", "").Replace("【", "").Replace("】", "");
            hzString = hzString.Replace("{", "").Replace("}", "").Replace("^", "").Replace("&", "_").Replace("=", "").Replace("~", "_").Replace("@", "_").Replace("￥", "");
            if (hzString.Length > maxLength)
            {
                hzString = hzString.Substring(0, maxLength);
            }
            Regex regex = new Regex(@"([a-zA-Z0-9\._]+)", RegexOptions.IgnoreCase);
            if (regex.IsMatch(hzString))
            {
                if (hzString.Equals(regex.Match(hzString).Groups[1].Value, StringComparison.OrdinalIgnoreCase))
                {
                    return hzString;
                }
            }
            // 匹配中文字符
            regex = new Regex("^[\u4e00-\u9fa5]$");
            byte[] array = new byte[2];
            string pyString = "";
            int chrAsc = 0;
            int i1 = 0;
            int i2 = 0;
            char[] noWChar = hzString.ToCharArray();

            for (int j = 0; j < noWChar.Length; j++)
            {
                // 中文字符
                if (regex.IsMatch(noWChar[j].ToString()))
                {
                    array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());
                    i1 = (short)(array[0]);
                    i2 = (short)(array[1]);
                    chrAsc = i1 * 256 + i2 - 65536;
                    if (chrAsc > 0 && chrAsc < 160)
                    {
                        pyString += noWChar[j];
                    }
                    else
                    {
                        // 修正部分文字
                        if (chrAsc == -9254) // 修正“圳”字
                            pyString += "Zhen";
                        else
                        {
                            for (int i = (pyValue.Length - 1); i >= 0; i--)
                            {
                                if (pyValue[i] <= chrAsc)
                                {
                                    pyString += pyName[i];
                                    break;
                                }
                            }
                        }
                    }
                }
                // 非中文字符
                else
                {
                    pyString += noWChar[j].ToString();
                }
            }
            return pyString;

        }
    }

    public class GetFirstZiMu
    {

        /// <summary> 
        /// 在指定的字符串列表CnStr中检索符合拼音索引字符串 
        /// </summary> 
        /// <param name="CnStr">汉字字符串</param> 
        /// <returns>相对应的汉语拼音首字母串</returns> 
        public static string GetSpellCode(string CnStr)
        {
            string strTemp = "";
            int iLen = CnStr.Length;
            int i = 0;

            for (i = 0; i <= iLen - 1; i++)
            {
                strTemp += GetCharSpellCode(CnStr.Substring(i, 1));
            }

            return strTemp;
        }


        /// <summary> 
        /// 得到一个汉字的拼音第一个字母，如果是一个英文字母则直接返回大写字母 
        /// </summary> 
        /// <param name="CnChar">单个汉字</param> 
        /// <returns>单个大写字母</returns> 
        private static string GetCharSpellCode(string CnChar)
        {
            long iCnChar;

            byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);

            //如果是字母，则直接返回 
            if (ZW.Length == 1)
            {
                return CnChar.ToUpper();
            }
            else
            {
                // get the array of byte from the single char 
                int i1 = (short)(ZW[0]);
                int i2 = (short)(ZW[1]);
                iCnChar = i1 * 256 + i2;
            }

            //expresstion 
            //table of the constant list 
            // 'A'; //45217..45252 
            // 'B'; //45253..45760 
            // 'C'; //45761..46317 
            // 'D'; //46318..46825 
            // 'E'; //46826..47009 
            // 'F'; //47010..47296 
            // 'G'; //47297..47613 

            // 'H'; //47614..48118 
            // 'J'; //48119..49061 
            // 'K'; //49062..49323 
            // 'L'; //49324..49895 
            // 'M'; //49896..50370 
            // 'N'; //50371..50613 
            // 'O'; //50614..50621 
            // 'P'; //50622..50905 
            // 'Q'; //50906..51386 

            // 'R'; //51387..51445 
            // 'S'; //51446..52217 
            // 'T'; //52218..52697 
            //没有U,V 
            // 'W'; //52698..52979 
            // 'X'; //52980..53640 
            // 'Y'; //53689..54480 
            // 'Z'; //54481..55289 

            // iCnChar match the constant 
            if ((iCnChar >= 45217) && (iCnChar <= 45252))
            {
                return "A";
            }
            else if ((iCnChar >= 45253) && (iCnChar <= 45760))
            {
                return "B";
            }
            else if ((iCnChar >= 45761) && (iCnChar <= 46317))
            {
                return "C";
            }
            else if ((iCnChar >= 46318) && (iCnChar <= 46825))
            {
                return "D";
            }
            else if ((iCnChar >= 46826) && (iCnChar <= 47009))
            {
                return "E";
            }
            else if ((iCnChar >= 47010) && (iCnChar <= 47296))
            {
                return "F";
            }
            else if ((iCnChar >= 47297) && (iCnChar <= 47613))
            {
                return "G";
            }
            else if ((iCnChar >= 47614) && (iCnChar <= 48118))
            {
                return "H";
            }
            else if ((iCnChar >= 48119) && (iCnChar <= 49061))
            {
                return "J";
            }
            else if ((iCnChar >= 49062) && (iCnChar <= 49323))
            {
                return "K";
            }
            else if ((iCnChar >= 49324) && (iCnChar <= 49895))
            {
                return "L";
            }
            else if ((iCnChar >= 49896) && (iCnChar <= 50370))
            {
                return "M";
            }

            else if ((iCnChar >= 50371) && (iCnChar <= 50613))
            {
                return "N";
            }
            else if ((iCnChar >= 50614) && (iCnChar <= 50621))
            {
                return "O";
            }
            else if ((iCnChar >= 50622) && (iCnChar <= 50905))
            {
                return "P";
            }
            else if ((iCnChar >= 50906) && (iCnChar <= 51386))
            {
                return "Q";
            }
            else if ((iCnChar >= 51387) && (iCnChar <= 51445))
            {
                return "R";
            }
            else if ((iCnChar >= 51446) && (iCnChar <= 52217))
            {
                return "S";
            }
            else if ((iCnChar >= 52218) && (iCnChar <= 52697))
            {
                return "T";
            }
            else if ((iCnChar >= 52698) && (iCnChar <= 52979))
            {
                return "W";
            }
            else if ((iCnChar >= 52980) && (iCnChar <= 53688))
            {
                return "X";
            }
            else if ((iCnChar >= 53689) && (iCnChar <= 54480))
            {
                return "Y";
            }
            else if ((iCnChar >= 54481) && (iCnChar <= 55289))
            {
                return "Z";
            }
            else return ("?");

        }
    }
}
